//
//  ListCollectionViewCell.m
//  EquesCat
//
//  Created by Chun Hung Cheung on 2024/12/17.
//

#import "ListCollectionViewCell.h"
@interface ListCollectionViewCell()
@property (nonatomic,strong)UIView *contrainView;
@property (nonatomic,strong)UIImageView *devicesImageview;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *nickLabel;
@end

@implementation ListCollectionViewCell

- (UIView *)contrainView{
    if (nil == _contrainView) {
         _contrainView = [[UIView alloc]init];
         _contrainView.userInteractionEnabled = YES;
        [self.contentView addSubview:_contrainView];
        [_contrainView mas_makeConstraints:^(MASConstraintMaker *make){
            make.edges.mas_equalTo(self);
        }];
    }
    return _contrainView;
}



- (UIImageView *)devicesImageview{
    if (!_devicesImageview) {
         _devicesImageview = [[UIImageView alloc]init];
         _devicesImageview.contentMode = UIViewContentModeCenter;
         _devicesImageview.userInteractionEnabled = YES;
        [self.contrainView addSubview:_devicesImageview];
        [_devicesImageview mas_makeConstraints:^(MASConstraintMaker *make){
            make.centerY.equalTo(self.contrainView.mas_centerY);
            make.right.equalTo(self.contrainView.mas_right).offset(-8);
            make.width.mas_equalTo(35);
            make.height.mas_equalTo(60);
        }];
    }
    return _devicesImageview;
}


#pragma mark 主设备的单元格信息
- (UILabel*)titleLabel
{
    if (!_titleLabel) {
         _titleLabel = [[UILabel alloc]init];
         _titleLabel.numberOfLines = 0;
        [_titleLabel setTextAlignment:NSTextAlignmentLeft];
        [_titleLabel setTextColor:[HexChangeRGB colorWithHexString:@"#333333"]];
        [_titleLabel setFont:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0]];
        [self.contrainView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make){
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
        }];
    }
    return _titleLabel;
}


#pragma mark 主设备的单元格信息
- (UILabel*)nickLabel
{
    if (!_nickLabel) {
        _nickLabel = [[UILabel alloc]init];
        _nickLabel.numberOfLines = 0;
        [_nickLabel setTextAlignment:NSTextAlignmentLeft];
        [_nickLabel setTextColor:[HexChangeRGB colorWithHexString:@"#333333"]];
        [_nickLabel setFont:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0]];
        [self.contrainView addSubview:_nickLabel];
        [_nickLabel mas_makeConstraints:^(MASConstraintMaker *make){
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.top.equalTo(self.contentView.mas_top).offset(10);
        }];
    }
    return _nickLabel;
}


- (void)setList:(FBDevicesList *)list
{
    _list = list;
    
    self.titleLabel.text = _list.status > 0 ? @"实时视频":@"设备离线";
    
    if (_list.role == EQUESCAT) {
        self.devicesImageview.image = [UIImage imageNamed:@"cat_list_pet_feeder"];
    }else {
        self.devicesImageview.image = [UIImage imageNamed:@"vl0_add_smart_lock_list"];
    }
    self.nickLabel.text = _list.nick.length > 0 ? _list.nick : _list.defaultNick;
}

@end
